package com.bjwl.web.contrlller.admin;

import com.bjwl.pojo.BranchStore;
import com.bjwl.pojo.Card;
import com.bjwl.pojo.CardDenomination;
import com.bjwl.pojo.vo.CardQueryVo;
import com.bjwl.service.AdminCardService;
import com.bjwl.service.BranchStoreService;
import com.bjwl.service.CardDenominationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.RandomAccess;

/**
 * @Author: dzx
 * @Date:Create：in 2020/5/11 14:11
 * @Description:
 * @Modified By：
 * @Version: 1.0
 */
@Controller
@RequestMapping("/admin")
public class AdminCardController {

    @Autowired
    private AdminCardService adminCardService;

    @Autowired
    private BranchStoreService branchStoreService;

    @Autowired
    private CardDenominationService cardDenominationService;

    @RequestMapping("/findAllCard")
    public String findAllCard(CardQueryVo vo, Model model, HttpSession httpSession){
        List<BranchStore> list = branchStoreService.getBranchStoreId();
        if(list instanceof RandomAccess){
            System.out.println("************************需要随机打印*************************");
        }
        httpSession.setAttribute("branchStoreS",list);
        model.addAttribute("pageBean",adminCardService.findAllCard(vo));
        return "main_oa/card-list";
    }

    @RequestMapping("/addCard")
    public @ResponseBody
    boolean addCard(@RequestBody CardQueryVo vo){
        return adminCardService.addCard(vo);
    }

    @RequestMapping("/editS")
    public String editS(Integer id, Model model) throws ParseException {
        Card card = adminCardService.editS(id);
        List<CardDenomination> list = cardDenominationService.findAll();
        model.addAttribute("card",card);
        model.addAttribute("cardD",list);
        return "main_oa/card-edit";
    }

    @RequestMapping("/editE")
    public @ResponseBody
    boolean editE(@RequestBody Card card){
        return adminCardService.updateCard(card);
    }

    @RequestMapping("/deleteCard")
    public @ResponseBody
    boolean deleteCard(@RequestBody Integer id){
        System.out.println(id+"***************************************");
        return adminCardService.deleteCard(id);
    }

}
